home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / prio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.5 KB  |  78 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  prio.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17. #ifndef PRIOH
  18. #define PRIOH
  19.  
  20. //------------------------------------------------------------------------------
  21. // priority queues implemented by fibonacci heaps 
  22. //
  23. // Stefan Naeher  (1989)
  24. //------------------------------------------------------------------------------
  25.  
  26. #include <LEDA/basic.h>
  27.  
  28. #ifndef FHEAPH
  29. #include <LEDA/f_heap.h>
  30. #endif
  31.  
  32. typedef f_heap_item pq_item;
  33.  
  34. #define priority_queue(ktype,itype) name3(itype,ktype,priority_queue)
  35.  
  36.  
  37. #define priority_queuedeclare2(ktype,itype)\
  38. \
  39. struct priority_queue(ktype,itype)  : public f_heap \
  40. {\
  41.   int  cmp(ent& x, ent& y) const { return compare(*(itype*)&(x),*(itype*)&y); }\
  42.   void print_key(ent& x)   const { Print(*(itype*)&x); }\
  43.   void print_inf(ent& x)   const { Print(*(ktype*)&x); }\
  44.   void clear_key(ent& x)   const { Clear(*(itype*)&x); }\
  45.   void clear_inf(ent& x)   const { Clear(*(ktype*)&x); }\
  46.   void copy_key(ent& x)    const { Copy(*(itype*)&x); }\
  47.   void copy_inf(ent& x)    const { Copy(*(ktype*)&x); }\
  48. \
  49.   pq_item insert(ktype k,itype i) { return f_heap::insert(Ent(i),Ent(k));}\
  50. \
  51.   void  del_min(ktype& k, itype& i)   { k = key(find_min());\
  52.                                         i = inf(find_min());\
  53.                                         f_heap::del_min(); }\
  54. \
  55.   ktype del_min()   { ktype x = key(find_min()); f_heap::del_min(); return x; }\
  56.   ktype delete_min(){ ktype x = key(find_min()); f_heap::del_min(); return x; }\
  57.   ktype key(pq_item x)      const { return ktype(f_heap::inf(x)); }\
  58.   itype inf(pq_item x)      const { return itype(f_heap::key(x)); }\
  59.   itype info(pq_item x)     const { return itype(f_heap::key(x)); }\
  60.   void  change_key(pq_item x, ktype k) { f_heap::change_inf(x,Ent(k)); }\
  61.   void  decrease_inf(pq_item x,itype i){ f_heap::decrease_key(x,Ent(i)); }\
  62. \
  63.   priority_queue(ktype,itype)()  {}\
  64.   priority_queue(ktype,itype)(const priority_queue(ktype,itype)& Q)\
  65.   : f_heap((f_heap&)Q)  {}\
  66. \
  67.   priority_queue(ktype,itype)& operator=(const priority_queue(ktype,itype)& Q)\
  68.   { f_heap::operator=((f_heap&)Q); return *this; }\
  69. \
  70.  ~priority_queue(ktype,itype)()  { clear(); }\
  71.  };
  72.  
  73. #define forall_pq_items(i,Q) for(i = (Q).first_item(); i; i=(Q).next_item(i))
  74.  
  75. #endif
  76.  
  77.